package util

import (
	"crypto/md5"
	"encoding/hex"
	"github.com/google/uuid"
	"os"
	"path/filepath"
)

func GetAppDir() string {
	dir, _ := filepath.Split(os.Args[0])
	return dir
}

func MD5(data []byte) string {
	h := md5.New()
	h.Write(data)
	return hex.EncodeToString(h.Sum(nil))
}

func MD5To16(data []byte) string {
	return MD5(data)[8:24]
}

func NewUidMD5To16(prefix string) string {
	var data = uuid.New().String()
	data = MD5To16([]byte(data))
	if len(prefix) > 0 {
		data = prefix + data
	}
	return data
}
